using ExtendedMvc.Ajax;
using ExtendedMvc.Html;

namespace ExtendedMvc.Elements {
	public class SubmitLink : LinkBase<SubmitLink> {
		private bool _skipValidation;
		private string _formId;
		private bool _disabled;

		public SubmitLink(string content, string formId)
			: base(content, null) {
			SetAttribute(HtmlAttribute.Type, "submit");
			_formId = formId;
		}

		public virtual SubmitLink Disabled(bool value = true) {
			_disabled = value;
			return this;
		}

		public virtual SubmitLink SkipValidation(bool value = true) {
			_skipValidation = value;
			return this;
		}

		protected override void Prepare() {
			Link(_disabled ? "javascript: return false;" : string.Format(_skipValidation ? JavaScriptHelper.Submit : JavaScriptHelper.SubmitWithValidation, _formId));
			if (_disabled) SetAttribute(HtmlAttribute.Disabled, HtmlAttribute.Disabled);
			base.Prepare();
		}
	}
}